package day19;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

public class LineNumberReaderDemo {

	public static void main(String[] args) {
		LineNumberReader lnr = null;

		try {
			lnr = new LineNumberReader(
					new FileReader(
							"D:\\MyProject\\javatest\\src\\day19\\BufferedReaderDemo.java"));
			String line = null;
			while((line = lnr.readLine()) != null) {
				System.out.println(lnr.getLineNumber()+"|" +line);
			}
		} catch (FileNotFoundException e) {
			throw new RuntimeException("系统文件未找到！");
		} catch (IOException e) {
			throw new RuntimeException("文件读取失败！");
		} finally {
			if (null != lnr) {
				try {
					lnr.close();
				} catch (IOException e) {
					throw new RuntimeException("行号读取缓冲流关闭失败！");
				}
			}
		}
	}
}
